

#include "BinarySearchTree.hpp"

void test()
{
    vector<int> v1({ 1,9,2,5,3,8,7,4,6 });
    BSTree::KeyTree<int> b1;
    for (auto e : v1)
    {
        b1.insert(e);
    }
    b1.InOrder();

    for (auto e : v1)
    {
        b1.erase(e);
        b1.InOrder();
    }
}

void test2()
{
    vector<int> v1({ 1,9,2,5,3,8,7,4,6 });
    BSTree::KeyTree<int> b1;
    for (auto e : v1)
    {
        b1.insert(e);
    }
    b1.InOrder();

    BSTree::KeyTree<int> b2 = b1;
    b2.InOrder();

    b1.insert(12);
    b1.insert(15);
    b1.insert(16);
    b1.insert(11);
    b1.insert(22);

    b1.InOrder();

    b2 = b1;

    b2.InOrder();
}

void test3()
{
    vector<int> v1({ 1,9,2,5,3,8,7,4,6 });
    BSTree::KeyTree<int> b1;
    for (auto e : v1)
    {
        b1.insertR(e);
    }
    b1.InOrder();

    for (auto e : v1)
    {
        b1.eraseR(e);
        b1.InOrder();
    }
}

void test4()
{
    BSTree::KVTree<string, string> b1;
    b1.insert("insert", "charu");
    b1.insert("erase", "shanchu");
    b1.insert("string", "zifuchuan");
    b1.insert("list", "lianbiao");
    b1.insert("hello", "nihao");
    b1.insert("sometime", "youshi");
    b1.insert("true", "zhengque");

    string str;
    while (cin >> str)
    {
        auto ret = b1.find(str);
        if (ret)
        {
            cout << ret->_value << endl;
        }
        else 
        {
            cout << "Not finded!" << endl;
        }
    }
}

int main()
{
    //test();
    //test2();
    //test3();
    test4();

    return 0;
}
